Take-home Exercise 3

In this Take-home Exericse, hedonic pricing models will be build to explain the factors affecting resale prcies of public housing in Singapore. The hedonic price models will be built using approriate Geographical Weighted Regression (GWR) methods.

Ngah Xin Yan https://github.com/nxinyan/
11-05-2021

Overview

When buying a house, it is generally a major investment for most people. There are many factors that affects the housing prices, such as inflation rates, economy of country, which are more global in nature. There are other factors that are specific to the properties itself also, which can be further divided to structural and locational factors. Structural factors are variables related to the property themselves such as the size, fitting, and tenure of the property. Locational factors are variables related to the neighbourhood of the properties such as proximity to childcare centre, public transport service and shopping centre.

The effect of housing factors in relation to price will be examined using hedonic pricing models. Ordinary Least Square (OLS) method is used to built the model, however it fails to take into consideration that spatial autocorrelation and spatial heterogeneity exist in geographic data sets such as housing transactions. The estimation of OLS of hedonic pricing models could lead to biased, inconsistent or inefficient results. GWR was introduced to calibrate hedonic price model for housing to due with this limitation.

Objective

To build hedonic pricing models to explain factors affecting the resale prices of public housing in Singapore. Appropriare GWR methods must be used to built these models.

Dataset Used

Installing and Loading the R packages

packages = c('olsrr', 'corrplot', 'ggpubr', 'sf', 'spdep', 'GWmodel', 'tmap', 'tidyverse', 'httr', 'sp')
for (p in packages){
  if(!require(p, character.only = T)){
    install.packages(p)
  }
  library(p,character.only = T)
}

Handling Geospatial Data

Importing Geospatial Data

childcare_sf <- st_read("data/geospatial/child-care-services-geojson.geojson")
Reading layer `child-care-services-geojson' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial\child-care-services-geojson.geojson' 
  using driver `GeoJSON'
Simple feature collection with 1545 features and 2 fields
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 103.6824 ymin: 1.248403 xmax: 103.9897 ymax: 1.462134
z_range:       zmin: 0 zmax: 0
Geodetic CRS:  WGS 84
eldercare_sf <- st_read(dsn = "data/geospatial", layer="ELDERCARE")
Reading layer `ELDERCARE' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 120 features and 19 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 14481.92 ymin: 28218.43 xmax: 41665.14 ymax: 46804.9
Projected CRS: SVY21 / Singapore TM
mrtlrt_sf <- st_read(dsn = "data/geospatial", layer="MRTLRTStnPtt")
Reading layer `MRTLRTStnPtt' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 171 features and 3 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 6138.311 ymin: 27555.06 xmax: 45254.86 ymax: 47854.2
Projected CRS: SVY21
park_sf <- st_read("data/geospatial/parks-geojson.geojson")
Reading layer `parks-geojson' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial\parks-geojson.geojson' 
  using driver `GeoJSON'
Simple feature collection with 350 features and 2 fields
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 103.6929 ymin: 1.214058 xmax: 104.0017 ymax: 1.461503
z_range:       zmin: 0 zmax: 0
Geodetic CRS:  WGS 84
presch_sf <- st_read("data/geospatial/pre-schools-location-geojson.geojson")
Reading layer `pre-schools-location-geojson' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial\pre-schools-location-geojson.geojson' 
  using driver `GeoJSON'
Simple feature collection with 1925 features and 2 fields
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 103.6824 ymin: 1.247759 xmax: 103.9897 ymax: 1.462134
z_range:       zmin: 0 zmax: 0
Geodetic CRS:  WGS 84
supermarket_sf <- st_read("data/geospatial/supermarkets-geojson.geojson")
Reading layer `supermarkets-geojson' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial\supermarkets-geojson.geojson' 
  using driver `GeoJSON'
Simple feature collection with 526 features and 2 fields
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 103.6258 ymin: 1.24715 xmax: 104.0036 ymax: 1.461526
z_range:       zmin: 0 zmax: 0
Geodetic CRS:  WGS 84
mpsz_sf <- st_read(dsn="data/geospatial",
               layer="MP14_SUBZONE_WEB_PL")
Reading layer `MP14_SUBZONE_WEB_PL' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 323 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
Projected CRS: SVY21

Checking for invalid geometries

length(which(st_is_valid(childcare_sf) == FALSE))
[1] 0
length(which(st_is_valid(eldercare_sf) == FALSE))
[1] 0
length(which(st_is_valid(mrtlrt_sf) == FALSE))
[1] 0
length(which(st_is_valid(park_sf) == FALSE))
[1] 0
length(which(st_is_valid(presch_sf) == FALSE))
[1] 0
length(which(st_is_valid(supermarket_sf) == FALSE))
[1] 0
length(which(st_is_valid(mpsz_sf) == FALSE))
[1] 9

No invalid geometries is observed in childcare_sf, eldercare_sf, mrtlrt_sf, presch_sf, park_sf and supermarket_sf data frames. However, mpsz_sf data frame consists of 9 invalid geometries. The invalid geometries will be removed in the mpsz_sf data frame using st_make_valid() and check for any invalid geometries again.

mpsz_sf <- st_make_valid(mpsz_sf)
length(which(st_is_valid(mpsz_sf) == FALSE))
[1] 0

Checking for missing values

childcare_sf[rowSums(is.na(childcare_sf))!=0,]
Simple feature collection with 0 features and 2 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Geodetic CRS:  WGS 84
[1] Name        Description geometry   
<0 rows> (or 0-length row.names)
eldercare_sf[rowSums(is.na(eldercare_sf))!=0,]
Simple feature collection with 120 features and 19 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 14481.92 ymin: 28218.43 xmax: 41665.14 ymax: 46804.9
Projected CRS: SVY21 / Singapore TM
First 10 features:
   fid OBJECTID ADDRESSBLO ADDRESSBUI ADDRESSPOS
1    1        1       <NA>       <NA>     601318
2    2        2       <NA>       <NA>     462509
3    3        3       <NA>       <NA>     640190
4    4        4       <NA>       <NA>     190005
5    5        5       <NA>       <NA>     160044
6    6        6       <NA>       <NA>     160117
7    8        8       <NA>       <NA>     731569
8    9        9       <NA>       <NA>     651210
9   10       10       <NA>       <NA>     540182
10  11       11       <NA>       <NA>     228080
                              ADDRESSSTR ADDRESSTYP DESCRIPTIO
1      318A Jurong East Avenue 1 #02-308       <NA>       <NA>
2  Blk 509B Bedok North Street 3 #02-157       <NA>       <NA>
3         Blk 190 Boon Lay Drive #01-242       <NA>       <NA>
4                    5 Beach Rd #02-4943       <NA>       <NA>
5             Blk 44 Beo Crescent #01-67       <NA>       <NA>
6     Blk 117 Jalan Bukit Merah #01-1683       <NA>       <NA>
7              569A Champion Way #01-346       <NA>       <NA>
8         210A Bukit Batok St 21 #01-294       <NA>       <NA>
9    Blk 182 Rivervale Crescent\n#01-311       <NA>       <NA>
10                        81 Wilkie Road       <NA>       <NA>
   HYPERLINK LANDXADDRE LANDYADDRE
1       <NA>          0          0
2       <NA>          0          0
3       <NA>          0          0
4       <NA>          0          0
5       <NA>          0          0
6       <NA>          0          0
7       <NA>          0          0
8       <NA>          0          0
9       <NA>          0          0
10      <NA>          0          0
                                                     NAME PHOTOURL
1                            Yuhua Senior Activity Centre     <NA>
2                                    THK SAC @ Kaki Bukit     <NA>
3                                      THK SAC @ Boon Lay     <NA>
4                  PEACE-Connect Senior Activity Centre@5     <NA>
5                                  THK SAC @ Beo Crescent     <NA>
6                                Silver ACE @ Bukit Merah     <NA>
7              Care Corner Senior Activity Centre (WL569)     <NA>
8     Fei Yue Senior Activity Centre (Bukit Batok Branch)     <NA>
9  COMNET Senior Activity Centre @ 182 Rivervale Crescent     <NA>
10                   Abdullah Shooker Jewish Welfare Home     <NA>
   ADDRESSFLO          INC_CRC FMEL_UPD_D ADDRESSUNI   X_ADDR
1        <NA> 2B0DB92FDD914FFC 2016-07-28       <NA> 16614.08
2        <NA> 82728FA30612F3FD 2016-07-28       <NA> 38803.81
3        <NA> DE7A8D4EA0BD1D9B 2016-07-28       <NA> 14481.92
4        <NA> A2C058FC5785F7FE 2016-07-28       <NA> 31505.35
5        <NA> 9DBFD51E056AEE70 2016-07-28       <NA> 27218.35
6        <NA> 169DABA5B6ECEA87 2016-07-28       <NA> 27278.94
7        <NA> 4DC6800E9BB385BE 2016-07-28       <NA> 23147.94
8        <NA> EFBD712DA5DD6FEC 2016-07-28       <NA> 18820.58
9        <NA> 6BB0D7698D7B4C7D 2016-07-28       <NA> 36446.37
10       <NA> EBA4B3E6F7F5B8F0 2016-07-28       <NA> 29544.78
     Y_ADDR                  geometry
1  36639.12 POINT (16614.08 36639.12)
2  35098.78 POINT (38803.81 35098.78)
3  36357.61 POINT (14481.92 36357.61)
4  31853.52 POINT (31505.35 31853.52)
5  30135.49 POINT (27218.35 30135.49)
6  29350.17 POINT (27278.94 29350.17)
7  45761.17 POINT (23147.94 45761.17)
8  36396.32 POINT (18820.58 36396.32)
9  41376.90  POINT (36446.37 41376.9)
10 31691.08 POINT (29544.78 31691.08)
mrtlrt_sf[rowSums(is.na(mrtlrt_sf))!=0,]
Simple feature collection with 0 features and 3 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21
[1] OBJECTID STN_NAME STN_NO   geometry
<0 rows> (or 0-length row.names)
park_sf[rowSums(is.na(park_sf))!=0,]
Simple feature collection with 0 features and 2 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Geodetic CRS:  WGS 84
[1] Name        Description geometry   
<0 rows> (or 0-length row.names)
presch_sf[rowSums(is.na(presch_sf))!=0,]
Simple feature collection with 0 features and 2 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Geodetic CRS:  WGS 84
[1] Name        Description geometry   
<0 rows> (or 0-length row.names)
supermarket_sf[rowSums(is.na(supermarket_sf))!=0,]
Simple feature collection with 0 features and 2 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Geodetic CRS:  WGS 84
[1] Name        Description geometry   
<0 rows> (or 0-length row.names)
mpsz_sf[rowSums(is.na(mpsz_sf))!=0,]
Simple feature collection with 0 features and 15 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21
 [1] OBJECTID   SUBZONE_NO SUBZONE_N  SUBZONE_C  CA_IND     PLN_AREA_N
 [7] PLN_AREA_C REGION_N   REGION_C   INC_CRC    FMEL_UPD_D X_ADDR    
[13] Y_ADDR     SHAPE_Leng SHAPE_Area geometry  
<0 rows> (or 0-length row.names)

Only eldercare_sf contains missing values. Columns with missing values are removed.

eldercare_sf = select(eldercare_sf, -3, -4, -7,-8, -9, -13, -14, -17)

Checking for missing values again

eldercare_sf[rowSums(is.na(eldercare_sf))!=0,]
Simple feature collection with 0 features and 11 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: SVY21 / Singapore TM
 [1] fid        OBJECTID   ADDRESSPOS ADDRESSSTR LANDXADDRE LANDYADDRE
 [7] NAME       INC_CRC    FMEL_UPD_D X_ADDR     Y_ADDR     geometry  
<0 rows> (or 0-length row.names)

Checking for duplicates

any(duplicated(childcare_sf))
[1] FALSE
any(duplicated(eldercare_sf))
[1] FALSE
any(duplicated(mrtlrt_sf))
[1] FALSE
any(duplicated(park_sf))
[1] FALSE
any(duplicated(presch_sf))
[1] FALSE
any(duplicated(supermarket_sf))
[1] FALSE
any(duplicated(mpsz_sf))
[1] FALSE

There is no duplicated in the data sets above.

Checking of coordinate reference system (CRS)

st_crs() of sf package is used to display the coordinate reference system information.

st_crs(childcare_sf)
Coordinate Reference System:
  User input: WGS 84 
  wkt:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
st_crs(eldercare_sf)
Coordinate Reference System:
  User input: SVY21 / Singapore TM 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
st_crs(mrtlrt_sf)
Coordinate Reference System:
  User input: SVY21 
  wkt:
PROJCRS["SVY21",
    BASEGEOGCRS["SVY21[WGS84]",
        DATUM["World Geodetic System 1984",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]],
            ID["EPSG",6326]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["Degree",0.0174532925199433]]],
    CONVERSION["unnamed",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]]]
st_crs(park_sf)
Coordinate Reference System:
  User input: WGS 84 
  wkt:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
st_crs(presch_sf)
Coordinate Reference System:
  User input: WGS 84 
  wkt:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
st_crs(supermarket_sf)
Coordinate Reference System:
  User input: WGS 84 
  wkt:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
st_crs(mpsz_sf)
Coordinate Reference System:
  User input: SVY21 
  wkt:
PROJCRS["SVY21",
    BASEGEOGCRS["SVY21[WGS84]",
        DATUM["World Geodetic System 1984",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]],
            ID["EPSG",6326]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["Degree",0.0174532925199433]]],
    CONVERSION["unnamed",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["Degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]]]

From the output above, there are datasets that has EPSG code of 4326. and 9001 The correct coordinate system code for SVY21 is 3414 instead of 4326 and 9001. st_transform() of sf package will be used to assign the correct EPSG code to all data frames.

childcare_sf <- st_transform(childcare_sf, 3414)
eldercare_sf <- st_transform(eldercare_sf, 3414)
mrtlrt_sf <- st_transform(mrtlrt_sf, 3414)
park_sf <- st_transform(park_sf, 3414)
presch_sf <- st_transform(presch_sf, 3414)
supermarket_sf <- st_transform(supermarket_sf, 3414)
mpsz_sf <- st_transform(mpsz_sf, 3414)

Checking CRS again

st_crs(childcare_sf)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
st_crs(eldercare_sf)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
st_crs(mrtlrt_sf)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
st_crs(park_sf)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
st_crs(presch_sf)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
st_crs(supermarket_sf)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]
st_crs(mpsz_sf)
Coordinate Reference System:
  User input: EPSG:3414 
  wkt:
PROJCRS["SVY21 / Singapore TM",
    BASEGEOGCRS["SVY21",
        DATUM["SVY21",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4757]],
    CONVERSION["Singapore Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",1.36666666666667,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",103.833333333333,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",1,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",28001.642,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",38744.572,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["northing (N)",north,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["easting (E)",east,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Cadastre, engineering survey, topographic mapping."],
        AREA["Singapore - onshore and offshore."],
        BBOX[1.13,103.59,1.47,104.07]],
    ID["EPSG",3414]]

All dataframes has the EPSG code of 3414 now.

Displaying basic information of the data frames

st_geometry(childcare_sf)
Geometry set for 1545 features 
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 11203.01 ymin: 25667.6 xmax: 45404.24 ymax: 49300.88
z_range:       zmin: 0 zmax: 0
Projected CRS: SVY21 / Singapore TM
First 5 geometries:
st_geometry(eldercare_sf)
Geometry set for 120 features 
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 14481.92 ymin: 28218.43 xmax: 41665.14 ymax: 46804.9
Projected CRS: SVY21 / Singapore TM
First 5 geometries:
st_geometry(mrtlrt_sf)
Geometry set for 171 features 
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 6138.311 ymin: 27555.06 xmax: 45254.86 ymax: 47854.2
Projected CRS: SVY21 / Singapore TM
First 5 geometries:
st_geometry(park_sf)
Geometry set for 350 features 
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 12373.11 ymin: 21869.93 xmax: 46735.95 ymax: 49231.09
z_range:       zmin: 0 zmax: 0
Projected CRS: SVY21 / Singapore TM
First 5 geometries:
st_geometry(presch_sf)
Geometry set for 1925 features 
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 11203.01 ymin: 25596.33 xmax: 45404.24 ymax: 49300.88
z_range:       zmin: 0 zmax: 0
Projected CRS: SVY21 / Singapore TM
First 5 geometries:
st_geometry(supermarket_sf)
Geometry set for 526 features 
Geometry type: POINT
Dimension:     XYZ
Bounding box:  xmin: 4901.188 ymin: 25529.08 xmax: 46948.22 ymax: 49233.6
z_range:       zmin: 0 zmax: 0
Projected CRS: SVY21 / Singapore TM
First 5 geometries:
st_geometry(mpsz_sf)
Geometry set for 323 features 
Geometry type: GEOMETRY
Dimension:     XY
Bounding box:  xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
Projected CRS: SVY21 / Singapore TM
First 5 geometries:

All geometry type are points except for mpsz_sf which

Visualisation of Geospatial Data

For childcare and eldercare

tmap_mode('view')
tm_shape(mpsz_sf) +
  tm_polygons() +
tm_shape(childcare_sf) +
  tm_dots(col="red") +
tm_shape(eldercare_sf) + 
  tm_dots(col="blue") +
  tm_view(set.zoom.limits = c(11,14))
tmap_mode('plot')

For mrtlrt and park

tmap_mode('view')
tm_shape(mpsz_sf) +
  tm_polygons() +
tm_shape(mrtlrt_sf) +
  tm_dots(col="red") +
tm_shape(park_sf) + 
  tm_dots(col="blue") +
  tm_view(set.zoom.limits = c(11,14))
tmap_mode('plot')

For pre school and supermarket

tmap_mode('view')
tm_shape(mpsz_sf) +
  tm_polygons() +
tm_shape(presch_sf) +
  tm_dots(col="red") +
tm_shape(supermarket_sf) + 
  tm_dots(col="blue") +
  tm_view(set.zoom.limits = c(11,14))
tmap_mode('plot')

Handling Aspatial Data

Importing Aspatial Data

Importing the dataset into R dataframe by using read_csv() function of readr package in tidyverse:

hdb_resale <- read_csv("data/aspatial/resale-flat-prices-based-on-registration-date-from-jan-2017-onwards.csv")

Use glimpse() to learn more about the attribute information in the data frame.

glimpse(hdb_resale)

For this Take-Home Exercise, we will only focus on four-room flats transacted from 1st January 2019 to 30th September 2020. Thus, the data set will be filtered according to the focus.

Filtering data frame for relevant data

filter() function of dplyr package in tidyverse is used to filter the data of 4-room flats from 1st January 2019 to 30th September 2020

mutate() function of dplyr package in tidyverse is used to add two new columns to hdbresale_jan19sep20: address (consisting of block and street name) and remaininglease_years (remaining lease in terms of years only)

hdb_resale_jan19sep20 <- hdb_resale %>%
                filter(month %in% c("2019-01", "2019-02", "2019-03", "2019-04", "2019-05", "2019-06", "2019-07", "2019-08", "2019-09", "2019-10", "2019-11", "2019-12","2020-01", "2020-02", "2020-03", "2020-04", "2020-05", "2020-06", "2020-07", "2020-08", "2020-09")) %>%
                filter(flat_type == "4 ROOM")

remaining_lease_list <- strsplit(hdb_resale_jan19sep20$remaining_lease, " ")
hdb_resale_jan19sep20$remaininglease_years <- 0
for (x in 1:length(remaining_lease_list)) {
  if (length(unlist(remaining_lease_list[x])) > 2) {
      year <- as.numeric(unlist(remaining_lease_list[x])[1])
      month <- as.numeric(unlist(remaining_lease_list[x])[3])
      hdb_resale_jan19sep20$remaininglease_years[x] <- year + round(month/12, 2)
  }
  else {
    year <- as.numeric(unlist(remaining_lease_list[x])[1])
    hdb_resale_jan19sep20$remaininglease_years[x] <- year
  }
}

hdb_resale_data <- hdb_resale_jan19sep20 %>%
                  mutate(hdb_resale_jan19sep20, address = paste(block, street_name)) %>%
                  select(month, town, flat_type, address, block, street_name, storey_range, floor_area_sqm, flat_model, lease_commence_date, remaining_lease, remaininglease_years, resale_price)
hdb_resale_data
# A tibble: 15,901 x 13
   month   town       flat_type address block street_name storey_range
   <chr>   <chr>      <chr>     <chr>   <chr> <chr>       <chr>       
 1 2019-01 ANG MO KIO 4 ROOM    204 AN~ 204   ANG MO KIO~ 01 TO 03    
 2 2019-01 ANG MO KIO 4 ROOM    175 AN~ 175   ANG MO KIO~ 07 TO 09    
 3 2019-01 ANG MO KIO 4 ROOM    543 AN~ 543   ANG MO KIO~ 01 TO 03    
 4 2019-01 ANG MO KIO 4 ROOM    118 AN~ 118   ANG MO KIO~ 04 TO 06    
 5 2019-01 ANG MO KIO 4 ROOM    411 AN~ 411   ANG MO KIO~ 04 TO 06    
 6 2019-01 ANG MO KIO 4 ROOM    546 AN~ 546   ANG MO KIO~ 10 TO 12    
 7 2019-01 ANG MO KIO 4 ROOM    428 AN~ 428   ANG MO KIO~ 07 TO 09    
 8 2019-01 ANG MO KIO 4 ROOM    173 AN~ 173   ANG MO KIO~ 04 TO 06    
 9 2019-01 ANG MO KIO 4 ROOM    607 AN~ 607   ANG MO KIO~ 10 TO 12    
10 2019-01 ANG MO KIO 4 ROOM    603 AN~ 603   ANG MO KIO~ 07 TO 09    
# ... with 15,891 more rows, and 6 more variables:
#   floor_area_sqm <dbl>, flat_model <chr>,
#   lease_commence_date <dbl>, remaining_lease <chr>,
#   remaininglease_years <dbl>, resale_price <dbl>

There is a total of 15901 4-room flat transactions from 1st January 2019 to 30 September 2020 after filtering.

It is noticed that street name such as “ST. GEORGE’S” has problem when obtaining the latitude and longitude in the later part. The short form “ST.” is replaced with its full name “SAINT”.

hdb_resale_data$address <- sub('ST\\.','SAINT',hdb_resale_data$address)

Getting coordinates (latitude and longitude) for each 4-room flat

To get the coordinates for each 4-room flat, the address column in hdb_resale_data is used in OneMap Search API which returns search results with both latitude and longitude. Obtain the result using GET() function of httr package and add the values of the new columns, LATITUDE and LONGITUDE respectively into each row of hdb_resale_data.

for (x in 1:nrow(hdb_resale_data)) {
  address <- hdb_resale_data[x,'address']
  
  url = paste('https://developers.onemap.sg/commonapi/search?searchVal=', address, '&returnGeom=Y&getAddrDetails=Y&pageNum=1')
  latlong_url <- URLencode(url)
  
  latlong <- GET(latlong_url)
  
  jsonlatlong <- content(latlong,as="parsed")
  
  if (length(jsonlatlong$results) > 0) {
    hdb_resale_data[x,'LATITUDE'] = jsonlatlong$results[[1]]$LATITUDE
    hdb_resale_data[x,'LONGITUDE'] = jsonlatlong$results[[1]]$LONGITUDE
  }
}

Checking the rows for any missing data in the LATITUDE and LONGITUDE column

is.na() is used to check for the total number of missing value (NA)

sum(is.na(hdb_resale_data$LATITUDE))
[1] 0
sum(is.na(hdb_resale_data$LONGITUDE))
[1] 0

There is no missing data observed.

Creating a csv to keep the results above

To avoid going through the long process above again, data will be exported to the new csv.

write.csv(hdb_resale_data, "data/aspatial/hdb_resale_latlong.csv", row.names = FALSE)

Structural Factors

Importing the updated csv file

resale_data <- read_csv("data/aspatial/hdb_resale_latlong.csv")

Remaining Lease

Obtain from the column remaininglease_years which was converted from remaining_lease into years as a unit instead of years and months.

lease <- resale_data$remaininglease_years

Floor Level

The floor level is provided in a range instead of individual levels. unique() of the base function is used to identify the unique level range.

length(unique(resale_data$storey_range))
[1] 17

There is 17 unique floor level range.

Locational Factors

Creating a simple feature data frame from an aspatial data frame

resale_data_sf <- st_as_sf(resale_data, 
                         coords = c("LONGITUDE", "LATITUDE"), crs=4326) %>%
  st_transform(crs = 3414)

Computing proximity matrix

Create a function to get the distance between the HDB Flat and factors mentioned in the dataset using st_distance() from sf package and dist() is used to calculate the euclidean distance

proximity <- function(df_1, df_2, var) {
  
  df_1_geometry <- st_coordinates(df_1$geometry)
  df_2_geometry <- st_coordinates(df_2$geometry)
  df_2_geometry <- df_2_geometry[,c(1,2)]
  dist_matrix <- spDists(df_1_geometry, df_2_geometry, longlat=FALSE)
  dist_matrix_df <- data.frame(dist_matrix) 
  dist_matrix_min <- dist_matrix_df %>% rowwise() %>% mutate(Min = min(c_across(1:(ncol(dist_matrix_df)))))
  df_1[,var] <- dist_matrix_min$Min/1000
  
  return(df_1)
}
resale_data_sf <- proximity(resale_data_sf, eldercare_sf, "PROX_ELDERCARE")
resale_data_sf <- proximity(resale_data_sf, park_sf, "PROX_PARK")
resale_data_sf <- proximity(resale_data_sf, childcare_sf, "PROX_CHILDCARE")
resale_data_sf <- proximity(resale_data_sf, mrtlrt_sf, "PROX_MRTLRT")
resale_data_sf <- proximity(resale_data_sf, presch_sf, "PROX_PRESCH")
resale_data_sf <- proximity(resale_data_sf, supermarket_sf, "PROX_SUPERMARKET")

Creating a shp file to keep the results above

resale_data_sf = select(resale_data_sf, -1, -2, -3, -5, -6, -9, -10, -11)
resale_data_sf = select(resale_data_sf, -10, -11)
st_write(resale_data_sf, "data/geospatial/resale_data_final_neww.shp")

Exploratory Data Analysis

Importing Final Dataset

resale_data_sf <- st_read(dsn="data/geospatial",
                          layer="resale_data_final_neww")
Reading layer `resale_data_final_neww' from data source 
  `C:\nxinyan\IS415\IS415_blog-2\_posts\2021-11-05-take-home-exercise-3\data\geospatial' 
  using driver `ESRI Shapefile'
Simple feature collection with 15901 features and 11 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 11597.31 ymin: 28217.39 xmax: 42623.63 ymax: 48741.06
Projected CRS: SVY21 / Singapore TM
resale_data_sf <- resale_data_sf %>%
  rename("AREA_SQM" = "flr_r_s", "remaininglease_years" = "rmnngl_", 
         "resale_price"= "rsl_prc", "PROX_PARK" = "PROX_PA", "PROX_CHILDCARE" = "PROX_CH", "PROX_MRTLRT" = "PROX_MR", "PROX_PRESCH" = "PROX_PR", "PROX_ELDERCARE" = "PROX_EL", "PROX_SUPERMARKET" = "PROX_SU")

EDA using statistical graphics

Plotting the distribution of resale_price by using appropriate Exploratory Data Analysis (EDA)

ggplot(data=resale_data_sf, aes(x=`resale_price`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

The figure above reveals a right skewed distribution. This means that more 4 room type units were transacted at relative lower prices.

Statistically, the skewed distribution can be normalised by using log transformation. mutate() of dplyr package is used too add a new variable called log_resale_price using a log transformation on the variable resale_price.

resale_data_sf <- resale_data_sf %>%
  mutate(`log_resale_price` = log(resale_price))

Plotting the distribution of log_resale_price

ggplot(data=resale_data_sf, aes(x=`log_resale_price`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

The distribution is relatively less skewed after the transformation.

Multiple Histogram Plots distribution of variables

Drawing 12 small multiple histograms (also known as trellis plot) by using ggarrange() of ggpubr package.

resale_data_sf$remaininglease_years <- as.numeric(resale_data_sf$remaininglease_years)
AREA_SQM <- ggplot(data=resale_data_sf, aes(x= `AREA_SQM`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

remaininglease_years <- ggplot(data=resale_data_sf, aes(x= `remaininglease_years`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

PROX_CHILDCARE <- ggplot(data=resale_data_sf, aes(x= `PROX_CHILDCARE`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

PROX_ELDERCARE <- ggplot(data=resale_data_sf, aes(x= `PROX_ELDERCARE`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

PROX_SUPERMARKET <- ggplot(data=resale_data_sf, aes(x= `PROX_SUPERMARKET`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

PROX_PRESCH <- ggplot(data=resale_data_sf, aes(x= `PROX_PRESCH`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

PROX_MRTLRT <- ggplot(data=resale_data_sf, aes(x= `PROX_MRTLRT`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

PROX_PARK <- ggplot(data=resale_data_sf, aes(x= `PROX_PARK`)) +
  geom_histogram(bins=20, color="black", fill="light blue")

ggarrange(remaininglease_years, PROX_PRESCH, PROX_PARK, PROX_MRTLRT, PROX_CHILDCARE, AREA_SQM, PROX_ELDERCARE, PROX_SUPERMARKET, ncol = 3, nrow = 3)

The distribution of the majority of the independent variables are right skewed, only remaininglease_years is slightly left skewed.

Drawing Statistical Point Map

Revealing the geospatial distribution 4-room type unit resale prices in Singapore using tmap package

tmap_mode("view")

tm_shape(mpsz_sf)+
  tm_polygons() +
tm_shape(resale_data_sf) +  
  tm_dots(col = "resale_price",
          alpha = 0.6,
          style="quantile") +
  tm_view(set.zoom.limits = c(11,14))

The units around the central area of Singapore tends to be dense with higher resale prices.

Hedonic Pricing Modelling in R

Building hedonic pricing models for 4 room type resale units using lm() of R base.

Multiple Linear Regression Method

Visualising the relationships of the independent variables

Before building a multiple regression model, it is important to ensure that the indepdent variables used are not highly correlated to each other. If these highly correlated independent variables are used in building a regression model by mistake, the quality of the model will be compromised. This phenominan is known as multicollinearity in statistics.

Correlation matrix is commonly used to visualise the relationships between the independent variables. Beside the pairs() of R, there are many packages support the display of a correlation matrix. In this section, the corrplot package will be used.

resale_data <- resale_data_sf %>%
  st_set_geometry(NULL)
corrplot(cor(resale_data[, 3:11]), diag = FALSE, order = "AOE",
         tl.pos = "td", tl.cex = 0.5, method = "number", type = "upper")

Leaving out PROX_PRESCH

Building the Hedonic Pricing Model

lm() is used to calibrate the multiple linear regression model.

resale.mlr <- lm(formula = resale_price ~ AREA_SQM + PROX_CHILDCARE + PROX_ELDERCARE  +  PROX_MRTLRT  + PROX_PARK  + PROX_SUPERMARKET + remaininglease_years, data=resale_data_sf)
summary(resale.mlr)

Call:
lm(formula = resale_price ~ AREA_SQM + PROX_CHILDCARE + PROX_ELDERCARE + 
    PROX_MRTLRT + PROX_PARK + PROX_SUPERMARKET + remaininglease_years, 
    data = resale_data_sf)

Residuals:
    Min      1Q  Median      3Q     Max 
-214805  -67983  -20254   38353  660989 

Coefficients:
                      Estimate Std. Error t value Pr(>|t|)    
(Intercept)          191603.69   13216.17  14.498   <2e-16 ***
AREA_SQM               1034.47     115.73   8.939   <2e-16 ***
PROX_CHILDCARE       146184.46   10346.42  14.129   <2e-16 ***
PROX_ELDERCARE       -44426.12    1214.47 -36.581   <2e-16 ***
PROX_MRTLRT          -44733.97    2126.01 -21.041   <2e-16 ***
PROX_PARK            -63365.91    1817.46 -34.865   <2e-16 ***
PROX_SUPERMARKET     -95100.52    5282.08 -18.004   <2e-16 ***
remaininglease_years   3422.08      66.34  51.587   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 100800 on 15893 degrees of freedom
Multiple R-squared:  0.2968,    Adjusted R-squared:  0.2964 
F-statistic: 958.1 on 7 and 15893 DF,  p-value: < 2.2e-16
resale.mlr1 <- lm(formula = resale_price ~ AREA_SQM + PROX_CHILDCARE + PROX_ELDERCARE  + PROX_MRTLRT  + PROX_PARK  + PROX_SUPERMARKET + remaininglease_years, data=resale_data_sf)

ols_regress(resale.mlr1)
                             Model Summary                              
-----------------------------------------------------------------------
R                       0.545       RMSE                    100754.567 
R-Squared               0.297       Coef. Var                   23.237 
Adj. R-Squared          0.296       MSE                10151482860.546 
Pred R-Squared          0.296       MAE                      74302.027 
-----------------------------------------------------------------------
 RMSE: Root Mean Square Error 
 MSE: Mean Square Error 
 MAE: Mean Absolute Error 

                                     ANOVA                                       
--------------------------------------------------------------------------------
                    Sum of                                                      
                   Squares           DF        Mean Square       F         Sig. 
--------------------------------------------------------------------------------
Regression    6.808133e+13            7       9.725905e+12    958.077    0.0000 
Residual      1.613375e+14        15893    10151482860.546                      
Total         2.294188e+14        15900                                         
--------------------------------------------------------------------------------

                                              Parameter Estimates                                               
---------------------------------------------------------------------------------------------------------------
               model          Beta    Std. Error    Std. Beta       t        Sig           lower         upper 
---------------------------------------------------------------------------------------------------------------
         (Intercept)    191603.686     13216.171                  14.498    0.000     165698.494    217508.879 
            AREA_SQM      1034.471       115.729        0.061      8.939    0.000        807.629      1261.314 
      PROX_CHILDCARE    146184.463     10346.421        0.097     14.129    0.000     125904.305    166464.621 
      PROX_ELDERCARE    -44426.119      1214.466       -0.245    -36.581    0.000     -46806.611    -42045.628 
         PROX_MRTLRT    -44733.966      2126.010       -0.144    -21.041    0.000     -48901.185    -40566.746 
           PROX_PARK    -63365.908      1817.455       -0.237    -34.865    0.000     -66928.326    -59803.490 
    PROX_SUPERMARKET    -95100.521      5282.081       -0.125    -18.004    0.000    -105453.997    -84747.045 
remaininglease_years      3422.085        66.336        0.366     51.587    0.000       3292.058      3552.111 
---------------------------------------------------------------------------------------------------------------

Checking for multicolinearity

ols_vif_tol(resale.mlr1)
             Variables Tolerance      VIF
1             AREA_SQM 0.9455218 1.057617
2       PROX_CHILDCARE 0.9436752 1.059687
3       PROX_ELDERCARE 0.9859465 1.014254
4          PROX_MRTLRT 0.9485682 1.054220
5            PROX_PARK 0.9596186 1.042081
6     PROX_SUPERMARKET 0.9241951 1.082023
7 remaininglease_years 0.8793716 1.137176

Since the VIF of the independent variables are less than 10. We can safely conclude that there are no sign of multicollinearity among the independent variables.

Test for Non-Linearity

ols_plot_resid_fit() of olsrr package is used to perform linearity assumption test.

ols_plot_resid_fit(resale.mlr1)

Test for Normality Assumption

ols_plot_resid_hist() of olsrr package to perform normality assumption test.

ols_plot_resid_hist(resale.mlr1)

Testing for Spatial Autocorrelation

mlr.output <- as.data.frame(resale.mlr1$residuals)
resale.res.sf <- cbind(resale_data_sf, 
                        resale.mlr1$residuals) %>%
rename(`MLR_RES` = `resale.mlr1.residuals`)
resale.sp <- as_Spatial(resale.res.sf)
resale.sp
class       : SpatialPointsDataFrame 
features    : 15901 
extent      : 11597.31, 42623.63, 28217.39, 48741.06  (xmin, xmax, ymin, ymax)
crs         : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
variables   : 13
names       :          address,  stry_rn, AREA_SQM, remaininglease_years, resale_price,         PROX_PARK,    PROX_CHILDCARE,       PROX_MRTLRT,       PROX_PRESCH, PROX_SUPERMARKET,   PROX_ELDERCARE, log_resale_price,           MLR_RES 
min values  :   1 CHAI CHEE RD, 01 TO 03,       74,                 45.5,       218000, 0.044164321280278,     1.0375877e-08, 0.022040732477443,     1.0375877e-08,   1.21715176e-07,    1.9894379e-08, 12.2922503417712, -214805.356074549 
max values  : 9B BOON TIONG RD, 49 TO 51,      138,                   97,      1186888,  2.41313695915468, 0.582025109809587,  2.13060636038504, 0.547386819517238, 1.57131703651196, 3.30163731686804, 13.9868453136219,   660988.54759932 
tmap_mode("view")
tm_shape(mpsz_sf)+
  tm_polygons(alpha = 0.4) +
tm_shape(resale.res.sf) +  
  tm_dots(col = "MLR_RES",
          alpha = 0.6,
          style="quantile") +
  tm_view(set.zoom.limits = c(11,14))
tmap_mode("plot")

The figure above reveal that there is sign of spatial autocorrelation.

To proof that our observation is indeed true, the Moran’s I test will be performed

First, we will compute the distance-based weight matrix by using dnearneigh() function of spdep.

nb <- dnearneigh(coordinates(resale.sp), 0, 1500, longlat = FALSE)
summary(nb)
Neighbour list object:
Number of regions: 15901 
Number of nonzero links: 10219360 
Percentage nonzero weights: 4.0418 
Average number of links: 642.6866 
Link number distribution:

   2    7   14   25   26   31   32   46   56   57   60   65   68   69 
   3    1   14   15    5    4    2   47    4    4    5    2    4    1 
  71   72   75   79   86   88   89   90   97   99  101  103  106  109 
  12    1    1   78    3    5    4    3    8    8    6    2    2    5 
 110  112  115  117  118  119  120  121  122  123  124  125  126  128 
   8    3    6    1    9    6    5    7    4   22    7   55   21   30 
 130  131  132  133  134  135  136  137  138  139  140  141  142  143 
   1   14    6   14    7    5    5    9    2   28    4    2    8   15 
 145  146  147  148  149  150  151  152  153  154  155  156  157  158 
   9    6   17    6    1    1   21   20   13    7    3    8    9    5 
 159  160  161  162  163  164  165  166  167  168  169  170  171  173 
  17    6    3    2   12    6    6    3   11    3   11    3    8   14 
 174  175  176  177  178  179  180  181  182  183  184  185  186  187 
   2   28   14   23   10   17   11    7    5   12   12    9   37   22 
 188  189  190  191  192  193  194  195  196  197  198  199  200  201 
  14    3    5    6   10    7    2    8    4    7   21    8   14   18 
 202  203  204  205  206  207  208  209  210  211  212  213  214  215 
  28    3   15   14    3    5   22    4    1    5    8    4   14   21 
 216  217  218  219  220  221  222  223  224  225  226  227  228  229 
   6    3    2   12   24   28   38    3   10   10    4   20   25    3 
 230  231  232  233  234  235  236  237  238  239  240  241  242  243 
  10   15    3   14   13   37   10    2   21   10   31   24    8    8 
 244  245  246  247  248  249  250  251  252  253  254  255  256  257 
  11   11    3   14   13   20    6   24    8   23   18   15   15   13 
 258  259  260  261  262  263  264  265  266  267  268  269  270  271 
   7    4    7   11   14    5   26   13    3   27   34   15    1   19 
 272  273  274  275  276  277  278  279  280  281  282  283  284  285 
  34   55   19   19   24   17   58   12   54   29   31   24   33   27 
 286  287  288  289  290  291  292  293  294  295  296  297  298  299 
  11   62   51   29   21   33   71   39   14   43    8   20   30   25 
 300  301  302  303  304  305  306  307  308  309  310  311  312  313 
  21   23   34   21   31   32   22   12   19    4   13   11   11   24 
 314  315  316  317  318  319  320  321  322  323  324  325  326  327 
   7   26   18   14   43   23   19   24   26   24   39   21   19   42 
 328  329  330  331  332  333  334  335  336  337  338  339  340  341 
  24   23   23   31   12   19   27   34    3   27   35   25   21   42 
 342  343  344  345  346  347  348  349  350  351  352  353  354  355 
   6   28   19   18   12   28   10   41   20   23   32   10   34   30 
 356  357  358  359  360  361  362  363  364  365  366  367  368  369 
  20    6   20   18   43   24    7   12   43   12   42   32   10   36 
 370  371  372  373  374  375  376  377  378  379  380  381  382  383 
   4   31   18   17   45   19   37   35   10   24   14   13   23   17 
 384  385  386  387  388  389  390  391  392  393  394  395  396  397 
   4   35   32   31   22   16   40   15   16   16   20   22   23   31 
 398  399  400  401  402  403  404  405  406  407  408  409  410  411 
  19   12   27   21   24   18   32    8   16   16   23    3   23   18 
 412  413  414  415  416  417  418  419  420  421  422  423  424  425 
  26   22    9   26   16   14   13   66   20   12   13   82   14   19 
 426  427  428  429  430  431  432  433  434  435  436  437  438  439 
  25   23   30   26    9   29   18   29   32   20   35   12   25   21 
 440  441  442  443  444  445  446  447  448  449  450  451  452  453 
  14   27   11   10    1   28   10   13   27   24   15   11   35   26 
 454  455  456  457  458  459  460  461  462  463  464  465  466  467 
  11   24   21   17   58   33    3   15   17    6   31   15    7   20 
 468  469  470  471  472  473  474  475  476  477  478  479  480  481 
  28    6   19   21    9   19   23    8   24   18   33   30   25   20 
 482  483  484  485  486  487  488  489  490  491  492  493  494  495 
   9    9    8   23   15   16   15   10   34    8    4   18   11   20 
 496  497  498  499  500  501  502  503  504  505  506  507  508  509 
   5   19    6    8   10    5    4   26   17   22   10   48   18    6 
 510  511  512  513  514  515  516  517  518  519  520  521  522  523 
  24   34   21   34    1   13   14    4    7    7    7    4    9   18 
 524  525  526  527  528  529  530  531  532  533  534  535  536  537 
  11   10    8   10    7   50   21   14   20   12   10   17   21    7 
 538  539  540  541  542  543  544  545  546  547  548  549  550  551 
   3    9    4    6    3   16   24   15   11    5    8   13    8   18 
 552  553  554  555  556  557  558  559  560  561  562  563  564  565 
   8    9    5   12    3   11   18   22   14    7    5   21   10   15 
 566  567  568  569  570  571  572  573  574  575  576  577  578  579 
  33   17   22   15   12   17    7    8   21   14   42    4   27   11 
 580  582  583  584  585  586  587  588  589  590  591  592  593  594 
  13   12   10   16    7   21   12    5   12   31   18   23    8   13 
 595  596  597  598  599  600  601  602  603  604  605  606  607  608 
  13   13   24   12    8   17   10    6   12   18   10    8   18   11 
 609  610  611  612  613  614  615  616  617  618  619  620  621  622 
  12   14   29   22    2    9   10    7   27   26   12    4   10    1 
 623  624  625  626  627  628  629  630  631  632  633  634  635  636 
   2   26    7   14   21   16    5    5    7    4    3   22    4   13 
 637  638  639  640  641  642  643  644  645  646  647  648  649  650 
  19   24    5    8    5   17    9    7   14    3   33   10    5   14 
 651  652  653  654  655  656  657  658  659  660  661  662  664  666 
   5   39    9    5   10   10    5    4    2   11   21    4   18    3 
 667  668  669  670  671  672  673  674  675  676  677  678  679  680 
   2    4   17   14   15    5    9    3    9   22    6   12   13   14 
 681  682  683  684  686  687  688  689  690  691  692  693  694  695 
   8    7    5   30   27    4   34    1   19   20    5    8   22    9 
 696  697  698  699  701  702  703  704  705  706  707  708  709  710 
   6   16   17   14    6   10    7   10   14   26    6   14    2    7 
 711  712  713  714  715  716  717  718  719  720  721  722  723  724 
   6    9    4    2   31   11    9   13    7   33   33    5   14   11 
 725  726  728  729  730  731  732  733  734  735  736  737  738  739 
   2    4    7    2    5    2   26    2   10    1   12    1    5    2 
 740  741  742  743  744  745  746  747  748  749  750  751  752  753 
   1   13    8   11   16    2    8   23   13   16   18    8    6   26 
 754  755  756  757  758  759  760  761  762  763  764  765  766  767 
   6   24   11   12    4   15    5   27   11    3    1   11    7    6 
 768  769  770  771  772  773  774  775  776  777  778  779  780  781 
   4   18   27   31    3   23   21    6    5   17   12   19   19   17 
 782  783  784  785  786  787  788  789  790  791  792  793  794  795 
  26    9   10   34   16   16   13    7    4   14   15   21   13    9 
 796  797  798  799  800  801  802  803  804  805  806  807  808  809 
   3   17   19    9    4    9   46   14   11    1    6   12   31    9 
 810  811  812  813  814  815  816  817  818  819  820  821  822  823 
  21   10   19   36    2   48    4   11   16    6    5    3   46   20 
 824  825  826  827  828  829  830  831  832  833  834  835  836  837 
  31    8   18    8   39   11    6    4    1   14   10    9   24   30 
 838  839  840  841  842  843  844  845  846  847  848  849  850  851 
  14    6   30   11   17    7    9   12    8   12   10   16   13   13 
 852  853  854  855  856  857  858  859  860  861  862  863  864  865 
  19   21   33   16   12    4    4   12   16    3    9   20   16    6 
 866  867  868  869  870  871  872  873  874  875  876  877  878  879 
  11   11   31    5   18   13   15    3    2    5    4    2   19    7 
 880  881  882  883  884  885  886  887  888  889  890  891  892  893 
  11    5    5   12   11    5    3   10   10    4    3   28   21   17 
 894  895  896  897  898  899  900  901  902  903  904  905  906  907 
   3    3    9    1    6   10   11   24    5   13   12    5   38   11 
 908  909  910  911  912  913  914  915  917  918  919  920  921  922 
   4    6    3    4   11   14    2    8    4    6    4   19    4   12 
 923  924  925  926  927  928  929  930  931  932  933  934  935  936 
  30   23    8    5    3    5    2   18    2   11    6   17    4    1 
 938  939  940  941  942  943  944  945  946  950  951  952  953  954 
  13   16   15    3    3   22    8    3    3    4    4    6    4   21 
 955  956  958  961  962  964  965  966  967  968  969  970  971  974 
   5    9    1    2    7    2    5    7   10    1    8   29   10    5 
 975  976  978  979  980  981  982  983  984  985  986  987  988  989 
  10    3    9    3   22    1    1   11   31    5   11    5    4    1 
 990  992  993  994  995  996  997  998  999 1000 1001 1002 1003 1005 
   2   24    6    1    5    1    2    5    4    6    1    8    5   20 
1008 1009 1010 1011 1012 1013 1014 1015 1018 1019 1020 1021 1022 1023 
   5    8   20    5    8    5    5    1   13    3   12   24   17    2 
1024 1025 1026 1027 1029 1030 1032 1033 1034 1035 1036 1037 1039 1041 
   8   16    9   11    7    4   13    4    2    3   29    6   14    6 
1043 1045 1046 1047 1048 1049 1050 1051 1053 1054 1055 1057 1059 1060 
  13    7    6    2    7    9    3   11    5    6   25    2    1   31 
1061 1062 1065 1066 1067 1068 1069 1070 1073 1074 1075 1080 1081 1084 
  14    1    3    7    5    1    8    9    3    6    2    1    9    5 
1086 1087 1088 1089 1092 1093 1094 1095 1096 1097 1098 1100 1103 1104 
  15    1    6    3    2    6   12    3    7   17    8   10    8    8 
1108 1111 1113 1114 1117 1118 1120 1122 1123 1124 1125 1127 1131 1133 
   3    5    2    4   21   20    5    6    9    6    4   12    8    1 
1135 1137 1138 1139 1140 1141 1143 1144 1145 1146 1147 1148 1149 1151 
  33    2    7    9    6    5   15   12   15    5   12    2   15    8 
1152 1153 1154 1156 1157 1158 1160 1161 1162 1163 1164 1165 1166 1167 
  11    2    7   21    6    8    1    9    7   14   10    3    9    2 
1168 1170 1171 1172 1173 1174 1175 1176 1177 1179 1180 1181 1182 1183 
  10   15    4   41   14    5   13   10   12   14   13   12    2    3 
1185 1186 1187 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 
   7    2    1   11    6   14    2    9   10    8    1    2   12    2 
1200 1201 1203 1204 1205 1206 1207 1208 1210 1213 1214 1216 1217 1218 
  20    1   10   18    6    5    4   13    4    5    8   16    3   11 
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1234 1235 
   2   19   45    5   41    2    7   14   14    9    6   15   11    4 
1236 1237 1238 1239 1240 1241 1242 1244 1245 1246 1247 1248 1250 1254 
   7   31   13   14    7    1    5    4    8   14   11    3    1    1 
1255 1256 1258 1259 1263 1264 1266 1267 1268 1269 1270 1271 1272 1273 
   3   12    3    1    6    6    1    7    3    6    7    6    5   14 
1274 1275 1279 1281 1282 1283 1284 1286 1287 1288 1289 1291 1292 1294 
   2   12   10   10    3   16    2   14    1    1    3   10    9    4 
1295 1296 1297 1302 1304 1305 1307 1308 1309 1310 1311 1312 1313 1314 
   4    5    4   14    3    4    3    7    8   18    1    8    6   30 
1315 1316 1317 1319 1322 1324 1325 1327 1328 1330 1331 1333 1334 1335 
   1    1   14    7   17    3    5    4    2   10    2   17    3    1 
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 
  10    5   14    8    7   27    1    1    9   12   13   18    3   18 
1351 1352 1353 1357 1358 1362 1363 1365 1368 1369 1370 1372 1373 1374 
   6   11   13    8    8   21    8    8   17   11    2    6    1   12 
1376 1377 1378 1379 1381 1382 1383 1384 1385 1386 1387 1390 1391 1392 
  10    3   12    5    6    5   24   10    6    4   10    8   12    5 
1394 1396 1397 1399 1400 1401 1403 1406 1407 1408 1410 1413 1414 1416 
   6    6   21    8    2    6    7   15    6    2   14    4    1   20 
1417 1421 1422 1423 1425 1426 1429 1431 1432 1434 1435 1437 1440 1442 
   4   18    1    1    2    3    1    2    2    1    1    1   11    2 
1445 1447 1452 1454 1458 1460 1461 1465 1466 1467 1468 1472 1473 1474 
  19    2   10    2    8   11    1    2    3    1    4    1    1    2 
1475 1476 1477 1479 1480 1481 1486 1488 1492 1493 1494 1495 1496 1497 
   5    1    2    1    2    2    1   19    4    3    1    4    4    1 
1498 1499 1500 1502 1507 1519 1526 1527 1528 1531 1534 1536 1540 1543 
  12    1    1    8    1    2    3    2    3    6    6    6    4    4 
1548 1549 1551 1552 1553 1561 1564 1565 1567 1569 1573 1577 1580 1583 
   2    3    2    1    7    4    2    3    3   12    2    1    2    4 
1587 1588 1593 1597 1598 1603 1604 1608 1617 1618 1624 1626 1637 1638 
   1    8    4    3    6    1    1    9    3    1    1    3    2   16 
1647 1654 1655 1676 1685 1695 1701 1705 1728 1734 1738 1743 1745 1752 
   1    3    4    1    1    1    1    5    1    1    3    1    4    3 
1758 1765 1771 1774 1775 1800 1808 1811 1817 1852 1875 1882 1922 1951 
   2    3    4    4    1    4    5    4    1    3    3    1    2    5 
1965 
   4 
3 least connected regions:
3093 4752 5564 with 2 links
4 most connected regions:
3260 8169 12559 13540 with 1965 links

Next, nb2listw() of spdep packge will be used to convert the output neighbours lists (i.e. nb) into a spatial weights.

nb_lw <- nb2listw(nb, style = 'W')
summary(nb_lw)
Characteristics of weights list object:
Neighbour list object:
Number of regions: 15901 
Number of nonzero links: 10219360 
Percentage nonzero weights: 4.0418 
Average number of links: 642.6866 
Link number distribution:

   2    7   14   25   26   31   32   46   56   57   60   65   68   69 
   3    1   14   15    5    4    2   47    4    4    5    2    4    1 
  71   72   75   79   86   88   89   90   97   99  101  103  106  109 
  12    1    1   78    3    5    4    3    8    8    6    2    2    5 
 110  112  115  117  118  119  120  121  122  123  124  125  126  128 
   8    3    6    1    9    6    5    7    4   22    7   55   21   30 
 130  131  132  133  134  135  136  137  138  139  140  141  142  143 
   1   14    6   14    7    5    5    9    2   28    4    2    8   15 
 145  146  147  148  149  150  151  152  153  154  155  156  157  158 
   9    6   17    6    1    1   21   20   13    7    3    8    9    5 
 159  160  161  162  163  164  165  166  167  168  169  170  171  173 
  17    6    3    2   12    6    6    3   11    3   11    3    8   14 
 174  175  176  177  178  179  180  181  182  183  184  185  186  187 
   2   28   14   23   10   17   11    7    5   12   12    9   37   22 
 188  189  190  191  192  193  194  195  196  197  198  199  200  201 
  14    3    5    6   10    7    2    8    4    7   21    8   14   18 
 202  203  204  205  206  207  208  209  210  211  212  213  214  215 
  28    3   15   14    3    5   22    4    1    5    8    4   14   21 
 216  217  218  219  220  221  222  223  224  225  226  227  228  229 
   6    3    2   12   24   28   38    3   10   10    4   20   25    3 
 230  231  232  233  234  235  236  237  238  239  240  241  242  243 
  10   15    3   14   13   37   10    2   21   10   31   24    8    8 
 244  245  246  247  248  249  250  251  252  253  254  255  256  257 
  11   11    3   14   13   20    6   24    8   23   18   15   15   13 
 258  259  260  261  262  263  264  265  266  267  268  269  270  271 
   7    4    7   11   14    5   26   13    3   27   34   15    1   19 
 272  273  274  275  276  277  278  279  280  281  282  283  284  285 
  34   55   19   19   24   17   58   12   54   29   31   24   33   27 
 286  287  288  289  290  291  292  293  294  295  296  297  298  299 
  11   62   51   29   21   33   71   39   14   43    8   20   30   25 
 300  301  302  303  304  305  306  307  308  309  310  311  312  313 
  21   23   34   21   31   32   22   12   19    4   13   11   11   24 
 314  315  316  317  318  319  320  321  322  323  324  325  326  327 
   7   26   18   14   43   23   19   24   26   24   39   21   19   42 
 328  329  330  331  332  333  334  335  336  337  338  339  340  341 
  24   23   23   31   12   19   27   34    3   27   35   25   21   42 
 342  343  344  345  346  347  348  349  350  351  352  353  354  355 
   6   28   19   18   12   28   10   41   20   23   32   10   34   30 
 356  357  358  359  360  361  362  363  364  365  366  367  368  369 
  20    6   20   18   43   24    7   12   43   12   42   32   10   36 
 370  371  372  373  374  375  376  377  378  379  380  381  382  383 
   4   31   18   17   45   19   37   35   10   24   14   13   23   17 
 384  385  386  387  388  389  390  391  392  393  394  395  396  397 
   4   35   32   31   22   16   40   15   16   16   20   22   23   31 
 398  399  400  401  402  403  404  405  406  407  408  409  410  411 
  19   12   27   21   24   18   32    8   16   16   23    3   23   18 
 412  413  414  415  416  417  418  419  420  421  422  423  424  425 
  26   22    9   26   16   14   13   66   20   12   13   82   14   19 
 426  427  428  429  430  431  432  433  434  435  436  437  438  439 
  25   23   30   26    9   29   18   29   32   20   35   12   25   21 
 440  441  442  443  444  445  446  447  448  449  450  451  452  453 
  14   27   11   10    1   28   10   13   27   24   15   11   35   26 
 454  455  456  457  458  459  460  461  462  463  464  465  466  467 
  11   24   21   17   58   33    3   15   17    6   31   15    7   20 
 468  469  470  471  472  473  474  475  476  477  478  479  480  481 
  28    6   19   21    9   19   23    8   24   18   33   30   25   20 
 482  483  484  485  486  487  488  489  490  491  492  493  494  495 
   9    9    8   23   15   16   15   10   34    8    4   18   11   20 
 496  497  498  499  500  501  502  503  504  505  506  507  508  509 
   5   19    6    8   10    5    4   26   17   22   10   48   18    6 
 510  511  512  513  514  515  516  517  518  519  520  521  522  523 
  24   34   21   34    1   13   14    4    7    7    7    4    9   18 
 524  525  526  527  528  529  530  531  532  533  534  535  536  537 
  11   10    8   10    7   50   21   14   20   12   10   17   21    7 
 538  539  540  541  542  543  544  545  546  547  548  549  550  551 
   3    9    4    6    3   16   24   15   11    5    8   13    8   18 
 552  553  554  555  556  557  558  559  560  561  562  563  564  565 
   8    9    5   12    3   11   18   22   14    7    5   21   10   15 
 566  567  568  569  570  571  572  573  574  575  576  577  578  579 
  33   17   22   15   12   17    7    8   21   14   42    4   27   11 
 580  582  583  584  585  586  587  588  589  590  591  592  593  594 
  13   12   10   16    7   21   12    5   12   31   18   23    8   13 
 595  596  597  598  599  600  601  602  603  604  605  606  607  608 
  13   13   24   12    8   17   10    6   12   18   10    8   18   11 
 609  610  611  612  613  614  615  616  617  618  619  620  621  622 
  12   14   29   22    2    9   10    7   27   26   12    4   10    1 
 623  624  625  626  627  628  629  630  631  632  633  634  635  636 
   2   26    7   14   21   16    5    5    7    4    3   22    4   13 
 637  638  639  640  641  642  643  644  645  646  647  648  649  650 
  19   24    5    8    5   17    9    7   14    3   33   10    5   14 
 651  652  653  654  655  656  657  658  659  660  661  662  664  666 
   5   39    9    5   10   10    5    4    2   11   21    4   18    3 
 667  668  669  670  671  672  673  674  675  676  677  678  679  680 
   2    4   17   14   15    5    9    3    9   22    6   12   13   14 
 681  682  683  684  686  687  688  689  690  691  692  693  694  695 
   8    7    5   30   27    4   34    1   19   20    5    8   22    9 
 696  697  698  699  701  702  703  704  705  706  707  708  709  710 
   6   16   17   14    6   10    7   10   14   26    6   14    2    7 
 711  712  713  714  715  716  717  718  719  720  721  722  723  724 
   6    9    4    2   31   11    9   13    7   33   33    5   14   11 
 725  726  728  729  730  731  732  733  734  735  736  737  738  739 
   2    4    7    2    5    2   26    2   10    1   12    1    5    2 
 740  741  742  743  744  745  746  747  748  749  750  751  752  753 
   1   13    8   11   16    2    8   23   13   16   18    8    6   26 
 754  755  756  757  758  759  760  761  762  763  764  765  766  767 
   6   24   11   12    4   15    5   27   11    3    1   11    7    6 
 768  769  770  771  772  773  774  775  776  777  778  779  780  781 
   4   18   27   31    3   23   21    6    5   17   12   19   19   17 
 782  783  784  785  786  787  788  789  790  791  792  793  794  795 
  26    9   10   34   16   16   13    7    4   14   15   21   13    9 
 796  797  798  799  800  801  802  803  804  805  806  807  808  809 
   3   17   19    9    4    9   46   14   11    1    6   12   31    9 
 810  811  812  813  814  815  816  817  818  819  820  821  822  823 
  21   10   19   36    2   48    4   11   16    6    5    3   46   20 
 824  825  826  827  828  829  830  831  832  833  834  835  836  837 
  31    8   18    8   39   11    6    4    1   14   10    9   24   30 
 838  839  840  841  842  843  844  845  846  847  848  849  850  851 
  14    6   30   11   17    7    9   12    8   12   10   16   13   13 
 852  853  854  855  856  857  858  859  860  861  862  863  864  865 
  19   21   33   16   12    4    4   12   16    3    9   20   16    6 
 866  867  868  869  870  871  872  873  874  875  876  877  878  879 
  11   11   31    5   18   13   15    3    2    5    4    2   19    7 
 880  881  882  883  884  885  886  887  888  889  890  891  892  893 
  11    5    5   12   11    5    3   10   10    4    3   28   21   17 
 894  895  896  897  898  899  900  901  902  903  904  905  906  907 
   3    3    9    1    6   10   11   24    5   13   12    5   38   11 
 908  909  910  911  912  913  914  915  917  918  919  920  921  922 
   4    6    3    4   11   14    2    8    4    6    4   19    4   12 
 923  924  925  926  927  928  929  930  931  932  933  934  935  936 
  30   23    8    5    3    5    2   18    2   11    6   17    4    1 
 938  939  940  941  942  943  944  945  946  950  951  952  953  954 
  13   16   15    3    3   22    8    3    3    4    4    6    4   21 
 955  956  958  961  962  964  965  966  967  968  969  970  971  974 
   5    9    1    2    7    2    5    7   10    1    8   29   10    5 
 975  976  978  979  980  981  982  983  984  985  986  987  988  989 
  10    3    9    3   22    1    1   11   31    5   11    5    4    1 
 990  992  993  994  995  996  997  998  999 1000 1001 1002 1003 1005 
   2   24    6    1    5    1    2    5    4    6    1    8    5   20 
1008 1009 1010 1011 1012 1013 1014 1015 1018 1019 1020 1021 1022 1023 
   5    8   20    5    8    5    5    1   13    3   12   24   17    2 
1024 1025 1026 1027 1029 1030 1032 1033 1034 1035 1036 1037 1039 1041 
   8   16    9   11    7    4   13    4    2    3   29    6   14    6 
1043 1045 1046 1047 1048 1049 1050 1051 1053 1054 1055 1057 1059 1060 
  13    7    6    2    7    9    3   11    5    6   25    2    1   31 
1061 1062 1065 1066 1067 1068 1069 1070 1073 1074 1075 1080 1081 1084 
  14    1    3    7    5    1    8    9    3    6    2    1    9    5 
1086 1087 1088 1089 1092 1093 1094 1095 1096 1097 1098 1100 1103 1104 
  15    1    6    3    2    6   12    3    7   17    8   10    8    8 
1108 1111 1113 1114 1117 1118 1120 1122 1123 1124 1125 1127 1131 1133 
   3    5    2    4   21   20    5    6    9    6    4   12    8    1 
1135 1137 1138 1139 1140 1141 1143 1144 1145 1146 1147 1148 1149 1151 
  33    2    7    9    6    5   15   12   15    5   12    2   15    8 
1152 1153 1154 1156 1157 1158 1160 1161 1162 1163 1164 1165 1166 1167 
  11    2    7   21    6    8    1    9    7   14   10    3    9    2 
1168 1170 1171 1172 1173 1174 1175 1176 1177 1179 1180 1181 1182 1183 
  10   15    4   41   14    5   13   10   12   14   13   12    2    3 
1185 1186 1187 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 
   7    2    1   11    6   14    2    9   10    8    1    2   12    2 
1200 1201 1203 1204 1205 1206 1207 1208 1210 1213 1214 1216 1217 1218 
  20    1   10   18    6    5    4   13    4    5    8   16    3   11 
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1234 1235 
   2   19   45    5   41    2    7   14   14    9    6   15   11    4 
1236 1237 1238 1239 1240 1241 1242 1244 1245 1246 1247 1248 1250 1254 
   7   31   13   14    7    1    5    4    8   14   11    3    1    1 
1255 1256 1258 1259 1263 1264 1266 1267 1268 1269 1270 1271 1272 1273 
   3   12    3    1    6    6    1    7    3    6    7    6    5   14 
1274 1275 1279 1281 1282 1283 1284 1286 1287 1288 1289 1291 1292 1294 
   2   12   10   10    3   16    2   14    1    1    3   10    9    4 
1295 1296 1297 1302 1304 1305 1307 1308 1309 1310 1311 1312 1313 1314 
   4    5    4   14    3    4    3    7    8   18    1    8    6   30 
1315 1316 1317 1319 1322 1324 1325 1327 1328 1330 1331 1333 1334 1335 
   1    1   14    7   17    3    5    4    2   10    2   17    3    1 
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 
  10    5   14    8    7   27    1    1    9   12   13   18    3   18 
1351 1352 1353 1357 1358 1362 1363 1365 1368 1369 1370 1372 1373 1374 
   6   11   13    8    8   21    8    8   17   11    2    6    1   12 
1376 1377 1378 1379 1381 1382 1383 1384 1385 1386 1387 1390 1391 1392 
  10    3   12    5    6    5   24   10    6    4   10    8   12    5 
1394 1396 1397 1399 1400 1401 1403 1406 1407 1408 1410 1413 1414 1416 
   6    6   21    8    2    6    7   15    6    2   14    4    1   20 
1417 1421 1422 1423 1425 1426 1429 1431 1432 1434 1435 1437 1440 1442 
   4   18    1    1    2    3    1    2    2    1    1    1   11    2 
1445 1447 1452 1454 1458 1460 1461 1465 1466 1467 1468 1472 1473 1474 
  19    2   10    2    8   11    1    2    3    1    4    1    1    2 
1475 1476 1477 1479 1480 1481 1486 1488 1492 1493 1494 1495 1496 1497 
   5    1    2    1    2    2    1   19    4    3    1    4    4    1 
1498 1499 1500 1502 1507 1519 1526 1527 1528 1531 1534 1536 1540 1543 
  12    1    1    8    1    2    3    2    3    6    6    6    4    4 
1548 1549 1551 1552 1553 1561 1564 1565 1567 1569 1573 1577 1580 1583 
   2    3    2    1    7    4    2    3    3   12    2    1    2    4 
1587 1588 1593 1597 1598 1603 1604 1608 1617 1618 1624 1626 1637 1638 
   1    8    4    3    6    1    1    9    3    1    1    3    2   16 
1647 1654 1655 1676 1685 1695 1701 1705 1728 1734 1738 1743 1745 1752 
   1    3    4    1    1    1    1    5    1    1    3    1    4    3 
1758 1765 1771 1774 1775 1800 1808 1811 1817 1852 1875 1882 1922 1951 
   2    3    4    4    1    4    5    4    1    3    3    1    2    5 
1965 
   4 
3 least connected regions:
3093 4752 5564 with 2 links
4 most connected regions:
3260 8169 12559 13540 with 1965 links

Weights style: W 
Weights constants summary:
      n        nn    S0      S1       S2
W 15901 252841801 15901 79.6504 64104.78

Next, lm.morantest() of spdep package will be used to perform Moran’s I test for residual spatial autocorrelation

lm.morantest(resale.mlr1, nb_lw)

    Global Moran I for regression residuals

data:  
model: lm(formula = resale_price ~ AREA_SQM + PROX_CHILDCARE +
PROX_ELDERCARE + PROX_MRTLRT + PROX_PARK + PROX_SUPERMARKET +
remaininglease_years, data = resale_data_sf)
weights: nb_lw

Moran I statistic standard deviate = 1180.9, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Observed Moran I      Expectation         Variance 
    6.263627e-01    -2.237904e-04     2.815204e-07 

Building Hedonic Pricing Models using GWmodel

Building Adaptive Bandwidth GWR Model

Computing the adaptive bandwidth

bw.ger() to determine the recommended data point to use.

bw_adaptive <- bw.gwr(formula = resale_price ~ AREA_SQM + PROX_CHILDCARE + PROX_ELDERCARE  +  PROX_MRTLRT  + PROX_PARK  + PROX_SUPERMARKET + remaininglease_years, data=resale.sp, approach="CV", kernel="gaussian",
                      adaptive=TRUE, longlat=FALSE)
Take a cup of tea and have a break, it will take a few minutes.
          -----A kind suggestion from GWmodel development group
Adaptive bandwidth: 9834 CV score: 1.382242e+14 
Adaptive bandwidth: 6086 CV score: 1.247869e+14 
Adaptive bandwidth: 3767 CV score: 1.091045e+14 
Adaptive bandwidth: 2337 CV score: 8.996241e+13 
Adaptive bandwidth: 1449 CV score: 6.330012e+13 
Adaptive bandwidth: 905 CV score: 4.483325e+13 
Adaptive bandwidth: 563 CV score: 3.59437e+13 
Adaptive bandwidth: 358 CV score: 2.974412e+13 
Adaptive bandwidth: 224 CV score: 2.481651e+13 
Adaptive bandwidth: 149 CV score: 2.18508e+13 
Adaptive bandwidth: 94 CV score: 1.908847e+13 
Adaptive bandwidth: 69 CV score: 1.744921e+13 
Adaptive bandwidth: 44 CV score: 1.618741e+13 
Adaptive bandwidth: 38 CV score: 1.589982e+13 
Adaptive bandwidth: 25 CV score: NaN 
Adaptive bandwidth: 37 CV score: 1.587646e+13 
Adaptive bandwidth: 45 CV score: 1.621724e+13 
Adaptive bandwidth: 40 CV score: 1.599975e+13 
Adaptive bandwidth: 43 CV score: 1.613535e+13 
Adaptive bandwidth: 41 CV score: 1.603582e+13 
Adaptive bandwidth: 42 CV score: 1.610025e+13 
Adaptive bandwidth: 41 CV score: 1.603582e+13 
Adaptive bandwidth: 41 CV score: 1.603582e+13 
Adaptive bandwidth: 40 CV score: 1.599975e+13 
Adaptive bandwidth: 40 CV score: 1.599975e+13 
Adaptive bandwidth: 39 CV score: 1.596165e+13 
Adaptive bandwidth: 39 CV score: 1.596165e+13 
Adaptive bandwidth: 38 CV score: 1.589982e+13 
Adaptive bandwidth: 38 CV score: 1.589982e+13 
Adaptive bandwidth: 37 CV score: 1.587646e+13 
bw_adaptive
[1] 37

The result shows that the 30 is the recommended data points to be used.

Constructing the adaptive bandwidth gwr model

Calibrating the gwr-based hedonic pricing model by using adaptive bandwidth and gaussian kernel.

gwr_adaptive <- gwr.basic(formula = resale_price ~ AREA_SQM + PROX_CHILDCARE + PROX_ELDERCARE  +  PROX_MRTLRT  + PROX_PARK  + PROX_SUPERMARKET + remaininglease_years, data=resale.sp, bw=bw_adaptive, 
                      kernel = 'gaussian', adaptive=TRUE, longlat = FALSE)

gwr_adaptive
   ***********************************************************************
   *                       Package   GWmodel                             *
   ***********************************************************************
   Program starts at: 2021-11-08 04:05:11 
   Call:
   gwr.basic(formula = resale_price ~ AREA_SQM + PROX_CHILDCARE + 
    PROX_ELDERCARE + PROX_MRTLRT + PROX_PARK + PROX_SUPERMARKET + 
    remaininglease_years, data = resale.sp, bw = bw_adaptive, 
    kernel = "gaussian", adaptive = TRUE, longlat = FALSE)

   Dependent (y) variable:  resale_price
   Independent variables:  AREA_SQM PROX_CHILDCARE PROX_ELDERCARE PROX_MRTLRT PROX_PARK PROX_SUPERMARKET remaininglease_years
   Number of data points: 15901
   ***********************************************************************
   *                    Results of Global Regression                     *
   ***********************************************************************

   Call:
    lm(formula = formula, data = data)

   Residuals:
    Min      1Q  Median      3Q     Max 
-214805  -67983  -20254   38353  660989 

   Coefficients:
                         Estimate Std. Error t value Pr(>|t|)    
   (Intercept)          191603.69   13216.17  14.498   <2e-16 ***
   AREA_SQM               1034.47     115.73   8.939   <2e-16 ***
   PROX_CHILDCARE       146184.46   10346.42  14.129   <2e-16 ***
   PROX_ELDERCARE       -44426.12    1214.47 -36.581   <2e-16 ***
   PROX_MRTLRT          -44733.97    2126.01 -21.041   <2e-16 ***
   PROX_PARK            -63365.91    1817.46 -34.865   <2e-16 ***
   PROX_SUPERMARKET     -95100.52    5282.08 -18.004   <2e-16 ***
   remaininglease_years   3422.08      66.34  51.587   <2e-16 ***

   ---Significance stars
   Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
   Residual standard error: 100800 on 15893 degrees of freedom
   Multiple R-squared: 0.2968
   Adjusted R-squared: 0.2964 
   F-statistic: 958.1 on 7 and 15893 DF,  p-value: < 2.2e-16 
   ***Extra Diagnostic information
   Residual sum of squares: 1.613375e+14
   Sigma(hat): 100735.6
   AIC:  411508.2
   AICc:  411508.2
   BIC:  395763.3
   ***********************************************************************
   *          Results of Geographically Weighted Regression              *
   ***********************************************************************

   *********************Model calibration information*********************
   Kernel function: gaussian 
   Adaptive bandwidth: 37 (number of nearest neighbours)
   Regression points: the same locations as observations are used.
   Distance metric: Euclidean distance metric is used.

   ****************Summary of GWR coefficient estimates:******************
                               Min.     1st Qu.      Median
   Intercept            -5.3515e+07 -3.6783e+05 -1.3664e+05
   AREA_SQM             -7.4232e+04  1.3573e+03  2.4038e+03
   PROX_CHILDCARE       -8.6336e+06 -6.2396e+04 -8.8187e+03
   PROX_ELDERCARE       -7.0994e+07 -5.1845e+04 -3.5796e+03
   PROX_MRTLRT          -6.1634e+07 -1.2045e+05 -5.6856e+04
   PROX_PARK            -1.4210e+08 -7.1165e+04 -1.0726e+04
   PROX_SUPERMARKET     -2.6410e+07 -5.4729e+04 -3.5929e+03
   remaininglease_years -2.8549e+04  2.5991e+03  4.8743e+03
                            3rd Qu.      Max.
   Intercept             6.3801e+04 343131414
   AREA_SQM              3.8975e+03    731939
   PROX_CHILDCARE        4.0001e+04  26782593
   PROX_ELDERCARE        4.3206e+04  14926581
   PROX_MRTLRT           4.3237e+03 126782624
   PROX_PARK             4.5622e+04   2763599
   PROX_SUPERMARKET      6.8562e+04  50423922
   remaininglease_years  7.3722e+03     37182
   ************************Diagnostic information*************************
   Number of data points: 15901 
   Effective number of parameters (2trace(S) - trace(S'S)): 1569.101 
   Effective degrees of freedom (n-2trace(S) + trace(S'S)): 14331.9 
   AICc (GWR book, Fotheringham, et al. 2002, p. 61, eq 2.33): 374374.8 
   AIC (GWR book, Fotheringham, et al. 2002,GWR p. 96, eq. 4.22): 372895.7 
   BIC (GWR book, Fotheringham, et al. 2002,GWR p. 61, eq. 2.34): 367922.1 
   Residual sum of squares: 1.315889e+13 
   R-square value:  0.9426425 
   Adjusted R-square value:  0.9363624 

   ***********************************************************************
   Program stops at: 2021-11-08 04:07:47 

The report shows that the adjusted r-square of the gwr is 0.8561 which is significantly better than the globel multiple linear regression model of 0.6472.

Visualising GWR Output

Converting SDF into sf data.frame

resale_sf_adaptive <- st_as_sf(gwr_adaptive$SDF) %>%
  st_transform(crs=3414)
resale_sf_adaptive_svy21 <- st_transform(resale_sf_adaptive, 3414)
resale_sf_adaptive_svy21  
Simple feature collection with 15901 features and 30 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 11597.31 ymin: 28217.39 xmax: 42623.63 ymax: 48741.06
Projected CRS: SVY21 / Singapore TM
First 10 features:
   Intercept  AREA_SQM PROX_CHILDCARE PROX_ELDERCARE PROX_MRTLRT
1  -157868.3 3133.3621    -147022.901     -32776.264   -68822.03
2  -279658.1 3963.0452     -43372.114     -29442.755   -36043.45
3  -323035.1 2512.1546      55061.701     -33305.943   -18836.75
4  -215384.1 3200.5968     -38212.118     -40150.354   -23415.50
5  -308732.5 3075.5033      13934.478      49147.040   -47641.35
6  -247313.8 1800.3448      51371.799     -29009.832   -24274.98
7  -195179.2 1239.0523     -16820.809       7384.359   -88875.72
8  -224997.6 2500.3319     -31019.463     -49513.271   -41486.54
9  -165324.3  966.8194      10296.783     -35214.449   -65043.83
10 -198095.1 1788.5190       6976.101     -44924.564   -59271.69
   PROX_PARK PROX_SUPERMARKET remaininglease_years      y     yhat
1  -45795.40         53953.18             6185.058 330000 378683.7
2   76828.11         15292.18             4856.214 360000 378359.3
3  -74973.23        -73923.88             9723.555 370000 371548.5
4   29550.77         11664.40             5265.310 375000 393300.7
5  -12366.00        -59108.12             7772.661 380000 375859.8
6  -78068.75        -70502.83             9596.168 380000 373830.0
7  -27275.01        -23180.13             9397.143 385000 407678.1
8   57911.52         12818.14             6527.046 395000 393448.3
9   57099.38         29538.61             7764.176 395000 376573.3
10  59123.98         23036.33             7116.027 395000 356543.4
     residual CV_Score Stud_residual Intercept_SE AREA_SQM_SE
1  -48683.703        0   -1.72394412     81929.81    753.3406
2  -18359.268        0   -0.62947921     69370.51    812.3544
3   -1548.463        0   -0.05424927    126502.14   1268.4779
4  -18300.702        0   -0.65035363     66482.69    784.5150
5    4140.180        0    0.14236916    171299.60   1719.3961
6    6170.015        0    0.21149819    112010.13   1088.0583
7  -22678.081        0   -0.76009877    103462.81   1008.9360
8    1551.706        0    0.05271283     59627.91    604.9326
9   18426.686        0    0.66303801     80496.04    832.9533
10  38456.602        0    1.40001762     74098.10    752.2140
   PROX_CHILDCARE_SE PROX_ELDERCARE_SE PROX_MRTLRT_SE PROX_PARK_SE
1           48373.23         52269.035       19118.68     36057.77
2           41348.24         18981.649       17441.25     23831.19
3           57796.76         14656.819       37755.24     42556.87
4           39116.90         18715.483       17707.39     26364.77
5           46361.09         41080.331       41229.52     37011.08
6           53998.15         13095.413       31095.15     35688.51
7           45456.58          9810.804       24824.49     28577.04
8           35497.44         16844.043       15193.54     19757.69
9           48653.99         20145.813       19201.16     27072.48
10          45760.40         19371.323       17766.27     24813.07
   PROX_SUPERMARKET_SE remaininglease_years_SE Intercept_TV
1             49047.27                288.6623    -1.926873
2             13982.80                892.9809    -4.031369
3             31763.49                333.2717    -2.553594
4             19243.78                588.2701    -3.239702
5             46397.53                518.2462    -1.802295
6             29675.54                310.3172    -2.207959
7             25274.75                273.7377    -1.886467
8             11573.45                381.8568    -3.773360
9             13657.79                895.0129    -2.053820
10            13132.55                758.7668    -2.673417
   AREA_SQM_TV PROX_CHILDCARE_TV PROX_ELDERCARE_TV PROX_MRTLRT_TV
1     4.159290        -3.0393443        -0.6270685     -3.5997265
2     4.878468        -1.0489471        -1.5511168     -2.0665632
3     1.980448         0.9526780        -2.2723855     -0.4989174
4     4.079714        -0.9768698        -2.1453015     -1.3223575
5     1.788711         0.3005641         1.1963643     -1.1555154
6     1.654640         0.9513621        -2.2152667     -0.7806677
7     1.228078        -0.3700412         0.7526762     -3.5801635
8     4.133241        -0.8738507        -2.9395123     -2.7305383
9     1.160713         0.2116329        -1.7479785     -3.3874950
10    2.377673         0.1524484        -2.3191273     -3.3361921
   PROX_PARK_TV PROX_SUPERMARKET_TV remaininglease_years_TV  Local_R2
1    -1.2700562           1.1000240               21.426626 0.8523970
2     3.2238472           1.0936423                5.438206 0.8059203
3    -1.7617186          -2.3273224               29.176063 0.9679448
4     1.1208432           0.6061388                8.950498 0.7845608
5    -0.3341163          -1.2739497               14.998008 0.8814405
6    -2.1875039          -2.3757892               30.923741 0.9644117
7    -0.9544380          -0.9171260               34.329006 0.9479739
8     2.9310880           1.1075472               17.092915 0.7971989
9     2.1091298           2.1627665                8.674932 0.7525302
10    2.3827757           1.7541398                9.378411 0.7884405
                    geometry
1  POINT (29179.92 38822.08)
2  POINT (28423.42 39745.94)
3  POINT (30550.38 39588.77)
4   POINT (28240.06 39477.6)
5  POINT (30443.27 38382.85)
6   POINT (30637.92 39516.9)
7  POINT (30347.48 38995.85)
8   POINT (28325.75 39700.7)
9  POINT (28611.87 40270.61)
10 POINT (28271.22 40241.11)
gwr.adaptive.output <- as.data.frame(gwr_adaptive$SDF)
resale_sf_adaptive <- cbind(resale.res.sf, as.matrix(gwr.adaptive.output))
glimpse(resale_sf_adaptive)
Rows: 15,901
Columns: 46
$ address                 <chr> "204 ANG MO KIO AVE 3", "175 ANG MO ~
$ stry_rn                 <chr> "01 TO 03", "07 TO 09", "01 TO 03", ~
$ AREA_SQM                <dbl> 92, 91, 92, 99, 92, 92, 92, 92, 93, ~
$ remaininglease_years    <dbl> 57.00, 61.50, 61.08, 58.33, 59.58, 6~
$ resale_price            <dbl> 330000, 360000, 370000, 375000, 3800~
$ PROX_PARK               <dbl> 0.7450859, 0.4294870, 0.7800777, 0.1~
$ PROX_CHILDCARE          <dbl> 1.909015e-01, 1.354044e-01, 8.016387~
$ PROX_MRTLRT             <dbl> 0.7039715, 0.4034297, 0.8899529, 0.2~
$ PROX_PRESCH             <dbl> 1.909015e-01, 1.167469e-01, 8.016387~
$ PROX_SUPERMARKET        <dbl> 0.2708222, 0.3101889, 0.3187560, 0.4~
$ PROX_ELDERCARE          <dbl> 0.2514065, 0.6318448, 1.0824168, 0.3~
$ log_resale_price        <dbl> 12.70685, 12.79386, 12.82126, 12.834~
$ MLR_RES                 <dbl> -64111.8690, -53161.4137, 30128.2131~
$ Intercept               <dbl> -157868.3, -279658.1, -323035.1, -21~
$ AREA_SQM.1              <dbl> 3133.3621, 3963.0452, 2512.1546, 320~
$ PROX_CHILDCARE.1        <dbl> -147022.9012, -43372.1139, 55061.701~
$ PROX_ELDERCARE.1        <dbl> -32776.264, -29442.755, -33305.943, ~
$ PROX_MRTLRT.1           <dbl> -68822.03, -36043.45, -18836.75, -23~
$ PROX_PARK.1             <dbl> -45795.3993, 76828.1113, -74973.2262~
$ PROX_SUPERMARKET.1      <dbl> 53953.177, 15292.178, -73923.879, 11~
$ remaininglease_years.1  <dbl> 6185.058, 4856.214, 9723.555, 5265.3~
$ y                       <dbl> 330000, 360000, 370000, 375000, 3800~
$ yhat                    <dbl> 378683.7, 378359.3, 371548.5, 393300~
$ residual                <dbl> -48683.703, -18359.268, -1548.463, -~
$ CV_Score                <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ~
$ Stud_residual           <dbl> -1.72394412, -0.62947921, -0.0542492~
$ Intercept_SE            <dbl> 81929.81, 69370.51, 126502.14, 66482~
$ AREA_SQM_SE             <dbl> 753.3406, 812.3544, 1268.4779, 784.5~
$ PROX_CHILDCARE_SE       <dbl> 48373.23, 41348.24, 57796.76, 39116.~
$ PROX_ELDERCARE_SE       <dbl> 52269.035, 18981.649, 14656.819, 187~
$ PROX_MRTLRT_SE          <dbl> 19118.68, 17441.25, 37755.24, 17707.~
$ PROX_PARK_SE            <dbl> 36057.77, 23831.19, 42556.87, 26364.~
$ PROX_SUPERMARKET_SE     <dbl> 49047.27, 13982.80, 31763.49, 19243.~
$ remaininglease_years_SE <dbl> 288.6623, 892.9809, 333.2717, 588.27~
$ Intercept_TV            <dbl> -1.926873, -4.031369, -2.553594, -3.~
$ AREA_SQM_TV             <dbl> 4.1592901, 4.8784685, 1.9804480, 4.0~
$ PROX_CHILDCARE_TV       <dbl> -3.0393443, -1.0489471, 0.9526780, -~
$ PROX_ELDERCARE_TV       <dbl> -0.6270685, -1.5511168, -2.2723855, ~
$ PROX_MRTLRT_TV          <dbl> -3.5997265, -2.0665632, -0.4989174, ~
$ PROX_PARK_TV            <dbl> -1.270056182, 3.223847173, -1.761718~
$ PROX_SUPERMARKET_TV     <dbl> 1.1000240, 1.0936423, -2.3273224, 0.~
$ remaininglease_years_TV <dbl> 21.426626, 5.438206, 29.176063, 8.95~
$ Local_R2                <dbl> 0.8523970, 0.8059203, 0.9679448, 0.7~
$ coords.x1               <dbl> 29179.92, 28423.42, 30550.38, 28240.~
$ coords.x2               <dbl> 38822.08, 39745.94, 39588.77, 39477.~
$ geometry                <POINT [m]> POINT (29179.92 38822.08), POI~
summary(gwr_adaptive$SDF$yhat)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 236091  355615  405671  433672  464970  984514 

Visualising local R2

tmap_mode("view")
tm_shape(mpsz_sf)+
  tm_polygons(alpha = 0.1) +
tm_shape(resale_sf_adaptive) +  
  tm_dots(col = "Local_R2",
          border.col = "gray60",
          border.lwd = 1) +
  tm_view(set.zoom.limits = c(11,14))
tmap_mode("plot")

By URA Plannign Region

tm_shape(mpsz_sf[mpsz_sf$REGION_N=="CENTRAL REGION", ])+
  tm_polygons()+
tm_shape(resale_sf_adaptive) + 
  tm_bubbles(col = "Local_R2",
           size = 0.15,
           border.col = "gray60",
           border.lwd = 1)